package com.example.mobile2021606176mhq0506;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.accessibility.AccessibilityViewCommand;

import java.net.URI;

public class MainActivity extends AppCompatActivity implements View.OnClickListener{

    private TextView tvMainTitle;
    private EditText edtxtMaininput;
    private Button btnMainIe;
    private Button btnMainCall;
    private Button btnMainCamera;
    private Button btnMainMap;
    private Intent intent;
    private String input;
    private Uri uri;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }
    public void onClick(View v){
        switch (v.getId()){
            case R.id.btn_main_ie:
                input=edtxtMaininput.getText().toString().trim();
                uri=Uri.parse(input);
                intent=new Intent(Intent.ACTION_VIEW,uri);
                startActivity(intent);
                break;
            case R.id.btn_main_call:
                input=edtxtMaininput.getText().toString().trim();
                uri=Uri.parse("tell:"+input);
                intent=new Intent(Intent.ACTION_DIAL,uri);
                startActivity(intent);
                break;
            case R.id.btn_main_camera:
                intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                startActivity(intent);
                break;
            case R.id.btn_main_map:
                input=edtxtMaininput.getText().toString().trim();
                uri=Uri.parse("geo："+input);
                intent=new Intent(Intent.ACTION_VIEW, uri);
                startActivity(intent);
                break;
        }
    }

    private void initView() {
        tvMainTitle = (TextView) findViewById(R.id.tv_main_title);
        edtxtMaininput = (EditText) findViewById(R.id.edtxt_main_input);
        btnMainIe = (Button) findViewById(R.id.btn_main_ie);
        btnMainCall = (Button) findViewById(R.id.btn_main_call);
        btnMainCamera = (Button) findViewById(R.id.btn_main_camera);
        btnMainMap = (Button) findViewById(R.id.btn_main_map);
        btnMainIe.setOnClickListener(this);
        btnMainCall.setOnClickListener(this);
        btnMainCamera.setOnClickListener(this);
        btnMainMap.setOnClickListener(this);
    }
}